#include "page_login.h"
#include "ui_page_login.h"

Page_login::Page_login(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Page_login)
    , m_ptrStumysql(nullptr)
{
    ui->setupUi(this);
    m_ptrStumysql = stumySql::getinstance();
    //m_ptrStumysql->init();//数据库的连接
}

Page_login::~Page_login()
{
    delete ui;
}

void Page_login::on_btn_login_clicked() //登录按钮
{
    //数据库查找用户名和密码
    QString strusername = ui->le_user->text();
    QString strpassword = ui->le_password->text();
    bool ok = m_ptrStumysql->isExist(strusername)
              && m_ptrStumysql->Selectpassword(strusername) == strpassword;
    if (ok) {
        //登录成功
        QMessageBox::information(NULL, "登录", "登录成功");
        strusername = strusername; // 将用户名保存到成员变量中
        emit sendLoginSuccess();
        emit sendLoginname(strusername); // 发送登录成功的消息和用户名
    } else {
        //登陆失败
        QMessageBox::information(NULL, "登录", "登录失败");
    }
}

void Page_login::on_btn_exit_clicked() //退出按钮
{
    exit(0);
}
